/**
 * Class:				WordsAdapter.java
 * 
 * Project:				Bio-inspired car commander
 * 
 * Subproject:			Word Detector
 * 
 * Date: 				Mai - Juillet 2011
 * 
 * Auteurs:				Bruno Da Silva
 * 						Thomas Jordan
 * 
 * Description:
 * 
 *	Adaptateur pour le words Manger 
 */
package ch.sda.bioinspiredcarcommander;

import java.util.List;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.TextView;

public class WordsAdapter extends BaseAdapter {
    private Context context;

    private List<String> listWords;

    public WordsAdapter(Context context, List<String> listWords) {
        this.context = context;
        this.listWords = listWords;
    }
	
	@Override
	public int getCount() {
		return listWords.size()+1;
	}

	@Override
	public Object getItem(int position) {
		if (position<listWords.size())
			return listWords.get(position);
		return null;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		String word = null;
		if (position < listWords.size()) {
			word = listWords.get(position);
			if (convertView == null) {
				LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
				convertView = inflater.inflate(R.layout.word_row, null);
			}
			TextView tvWord = (TextView) convertView.findViewById(R.id.tvWord);
			tvWord.setText(word);
			
			// Set the onClick Listener on this button
			ImageButton btnDelete = (ImageButton)convertView.findViewById(R.id.btnDelete);
			btnDelete.setOnClickListener(new View.OnClickListener() {
				
				@Override
				public void onClick(View v) {
					Log.v("LOL", "Want to delete");
				}
			});
		}
		else {
			if (convertView == null) {
				LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
				convertView = inflater.inflate(R.layout.word_row_plus, null);
			}
		}
		


        return convertView;
	}

}
